#include "mainwindow.h"

#include <QApplication>
#include <QCommandLineParser>
#include <QFile>
#include <QLocale>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QFile styleF;
    QString qssStr;
    QTranslator translator;
    QCommandLineParser parser;

    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "ISAP-server_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }

    // Версия приложения по -v или --version, помощь -h или --help и прочие параметры
    a.setApplicationName(QCoreApplication::translate("main", "Judicial terminal"));
    a.setApplicationVersion(VERSION_STRING);
    parser.setApplicationDescription(QCoreApplication::translate("main", "Sports referee terminal for competitions"));
    parser.addHelpOption();
    parser.addVersionOption();
    //parser.addPositionalArgument("ip", QCoreApplication::translate("main", "IP address"));
    QCommandLineOption JudgesNumber(QStringList() << "j" << "judge-number",
            QCoreApplication::translate("main", "Specify the number of the judge who will use the terminal."),
            QCoreApplication::translate("main", "number"));
    QCommandLineOption ipaddrcl(QStringList() << "i" << "ip-address",
            QCoreApplication::translate("main", "Specify the IP address of the server."), "ip");

    parser.addOption(JudgesNumber);
    parser.addOption(ipaddrcl);
    parser.process(a);
    //const QStringList args = parser.positionalArguments();
    QString jnumber = parser.value(JudgesNumber);
    QString ipaddr = parser.value(ipaddrcl);

    // Подключения файла стилей
    styleF.setFileName(":/styles.css");
    styleF.open(QFile::ReadOnly);
    qssStr = styleF.readAll();
    a.setStyleSheet(qssStr);

    MainWindow w;
    w.show();
    return a.exec();
}
